package com.slipper.qmt.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TaskManager {
    private static final Logger logger = LoggerFactory.getLogger(TaskManager.class);

    private static final TaskManager instance = new TaskManager();
    private final TaskList taskList;
    private final Consumer consumer;

    private TaskManager() {
        synchronized (TaskManager.class) {
            this.taskList = new TaskList();
            this.consumer = new Consumer(this.taskList);
            consumer.start();
        }
    }

    public void product(Object data) {
        try {
            taskList.product(data);
        } catch (Exception e) {
            logger.error("添加到消息队列出错：{}", data, e);
        }
    }

    public void shutdown() {
        this.taskList.clear();
        this.consumer.shutdown();
    }

    public static void add(Object data) {
        instance.product(data);
    }
}
